<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>简易计算器</title>
		<style type="text/css">
			div {
				margin-left: 70px;
			}
			div>input{
				margin: 10px;
			}
		</style>
	</head>
	<body>
		<form action="#">
			第一个数：<input type="text" id="one"><br>
			第二个数：<input type="text" id="two">
			<div>
				<input type="button" value="+" id="add">
				<input type="button" value="-" id="sub">
				<input type="button" value="*" id="mul">
				<input type="button" value="/" id="divi">
			</div>
			计算结果：<input type="text" id="three">
		</form>
		<script type="text/javascript">
			var btn = document.querySelectorAll("input[type=button]");
			for (var i = 0; i < btn.length; i++) {
				btn[i].addEventListener('click', addf, false)
			}
			function addf(event){
				var otarget;
				if(window.event){
					event = window.event
					otarget = event.srcElement
				}else{
					otarget = event.target
				}
				var str1 = document.getElementById("one").value
				var str2 = document.getElementById("two").value
				var result = document.getElementById("three");
				var numx = Math.pow(10,Math.max(str1.length - str1.indexOf("."),str2.length - str2.indexOf("."))) 
				if(otarget.value == "*"|| otarget.value == "/"){
					result.value = (eval(str1 * numx + otarget.value + str2 * numx))/(eval( numx + otarget.value + numx));
				}else{
					result.value = (eval(str1 * numx + otarget.value + str2 * numx))/numx;
				}
			}
		</script>
	</body>
</html>